{% extends "base.html" %}

{% block title %}管理作者{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-3">
    <h2 class="mb-0">作者总览</h2>
    <a href="{% url 'add_author' %}" class="btn btn-primary">
        <i class="fas fa-user-plus"></i> 添加新作者
    </a>
</div>

<div class="card shadow-sm">
    <div class="list-group list-group-flush">
        {% for author in authors %}
        <div class="list-group-item">
            <div class="d-flex w-100 justify-content-between align-items-center">
                <div>
                    <h5 class="mb-1">{{ author.name }}</h5>
                    <p class="mb-1 text-muted text-truncate" style="max-width: 600px;">
                        {{ author.biography|default:"暂无生平简介。" }}
                    </p>
                    <small class="text-muted">{{ author.books.count }} 本关联作品</small>
                </div>
                <div class="ms-3">
                    <a href="{% url 'edit_author' author.pk %}" class="btn btn-sm btn-outline-secondary mb-1 d-block">编辑</a>
                    <a href="{% url 'delete_author' author.pk %}" class="btn btn-sm btn-outline-danger d-block">删除</a>
                </div>
            </div>
        </div>
        {% empty %}
        <div class="list-group-item text-center p-3">
            <p class="mb-0">图书馆里还没有录入任何作者信息。</p>
        </div>
        {% endfor %}
    </div>
</div>

<!-- 分页导航 -->
{% if is_paginated %}
<nav aria-label="Page navigation" class="mt-4">
    <ul class="pagination justify-content-center">
        {% if page_obj.has_previous %}
            <li class="page-item"><a class="page-link" href="?page=1">&laquo; 首页</a></li>
            <li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">上一页</a></li>
        {% endif %}

        <li class="page-item disabled"><span class="page-link">第 {{ page_obj.number }} 页, 共 {{ page_obj.paginator.num_pages }} 页</span></li>

        {% if page_obj.has_next %}
            <li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">下一页</a></li>
            <li class="page-item"><a class="page-link" href="?page={{ page_obj.paginator.num_pages }}">尾页 &raquo;</a></li>
        {% endif %}
    </ul>
</nav>
{% endif %}
{% endblock %}